<template>
    <div id="echarts" style="width: 600px; height: 400px"></div>
</template>

<script setup lang="ts">
import { onMounted } from "vue";
import echarts from "../echart/index";
import { EChartsOption } from "../echart/index";

onMounted(() => {
    var chartDom = document.getElementById("echarts")!;
    if (chartDom) {
        var myChart = echarts.init(chartDom);
        var option: EChartsOption = {
            title: {
                text: "第一个 ECharts 实例",
            },
            tooltip: {},
            legend: {
                data: ["销量"],
            },
            xAxis: {
                data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
            },
            yAxis: {},
            series: [
                {
                    name: "销量",
                    type: "bar",
                    data: [5, 20, 36, 10, 10, 20],
                },
            ],
        };
        // 使用刚指定的配置项和数据显示图表。// “option && ” 避免option为空时出错
        option && myChart.setOption(option);
    } else {
        // 处理无法找到元素的情况
        console.error("无法找到 ID 为 'main' 的元素");
    }


})

</script>

<style lang="less" scoped></style>
